package com.cookiesoft.activity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cookiesoft.common.annotation.Log;
import com.cookiesoft.common.core.controller.BaseController;
import com.cookiesoft.common.core.domain.AjaxResult;
import com.cookiesoft.common.enums.BusinessType;
import com.cookiesoft.activity.domain.ZhenCoupons;
import com.cookiesoft.activity.service.IZhenCouponsService;
import com.cookiesoft.common.utils.poi.ExcelUtil;
import com.cookiesoft.common.core.page.TableDataInfo;

/**
 * 优惠券Controller
 *
 * @author anc
 * @date 2024-11-06
 */
@CrossOrigin
@RestController
@RequestMapping("/activity/discount" )
public class ZhenCouponsController extends BaseController {
    @Autowired
    private IZhenCouponsService zhenCouponsService;

/**
 * 查询优惠券列表
 */
@PreAuthorize("@ss.hasPermi('activity:discount:list')" )
@GetMapping("/list" )
    public TableDataInfo list(ZhenCoupons zhenCoupons) {
        startPage();
        List<ZhenCoupons> list = zhenCouponsService.selectZhenCouponsList(zhenCoupons);
        return getDataTable(list);
    }

    /**
     * 导出优惠券列表
     */
    @PreAuthorize("@ss.hasPermi('activity:discount:export')" )
    @Log(title = "优惠券" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ZhenCoupons zhenCoupons) {
        List<ZhenCoupons> list = zhenCouponsService.selectZhenCouponsList(zhenCoupons);
        ExcelUtil<ZhenCoupons> util = new ExcelUtil<ZhenCoupons>(ZhenCoupons. class);
        util.exportExcel(response, list, "优惠券数据" );
    }

    /**
     * 获取优惠券详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:discount:query')" )
    @GetMapping(value = "/{couponId}" )
    public AjaxResult getInfo(@PathVariable("couponId" ) Long couponId) {
        return success(zhenCouponsService.selectZhenCouponsByCouponId(couponId));
    }

    /**
     * 新增优惠券
     */
    @PreAuthorize("@ss.hasPermi('activity:discount:add')" )
    @Log(title = "优惠券" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhenCoupons zhenCoupons) {
        return toAjax(zhenCouponsService.insertZhenCoupons(zhenCoupons));
    }

    /**
     * 修改优惠券
     */
    @PreAuthorize("@ss.hasPermi('activity:discount:edit')" )
    @Log(title = "优惠券" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhenCoupons zhenCoupons) {
        return toAjax(zhenCouponsService.updateZhenCoupons(zhenCoupons));
    }

    /**
     * 删除优惠券
     */
    @PreAuthorize("@ss.hasPermi('activity:discount:remove')" )
    @Log(title = "优惠券" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{couponIds}" )
    public AjaxResult remove(@PathVariable Long[] couponIds) {
        return toAjax(zhenCouponsService.deleteZhenCouponsByCouponIds(couponIds));
    }
}
